package com.sk.weichat.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.AppConstant;
import com.sk.weichat.MyApplication;
import com.sk.weichat.R;
import com.sk.weichat.adapter.FriendHeadAdapter;
import com.sk.weichat.bean.RoamBean;
import com.sk.weichat.bean.User;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.ui.me.PersonalCenterActivity;
import com.sk.weichat.util.DateUtils;
import com.sk.weichat.util.DisplayUtil;
import com.sk.weichat.util.ScreenUtil;
import com.sk.weichat.util.TimeUtils;

import java.util.Date;
import java.util.List;


/**
 * 消息保存时间
 */
public class MsgSyncDaysDialog extends Dialog  {
    private  List<RoamBean> mRoamList;
    private OnMsgSaveDaysDialogClickListener mOnMsgSaveDaysDialogClickListener;
    private RoamAdapter mRoamAdapter;

    public MsgSyncDaysDialog(Context context, List<RoamBean> roamList, OnMsgSaveDaysDialogClickListener onMsgSaveDaysDialogClickListener) {
        super(context, R.style.BottomDialog);
        this.mOnMsgSaveDaysDialogClickListener = onMsgSaveDaysDialogClickListener;
        this.mRoamList=roamList;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.msg_sync_days_dialog);
        setCanceledOnTouchOutside(true);
        initView();
    };

    private void initView() {
        RecyclerView roamRecyclerView = findViewById(R.id.recycler_roam);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        roamRecyclerView.setLayoutManager(manager);
        mRoamAdapter = new RoamAdapter(R.layout.item_roam_recyclerview, mRoamList);
        roamRecyclerView.setAdapter(mRoamAdapter);

        mRoamAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.tv_roam:
                        dismiss();
                        mOnMsgSaveDaysDialogClickListener.itemClick(mRoamList.get(position).getRoamingTime(),mRoamList.get(position).getRoamingTimeStr());
                        break;
                }
            }
        });

        Window o = getWindow();
        WindowManager.LayoutParams lp = o.getAttributes();
        // x/y坐标
        // lp.x = 100;
        // lp.y = 100;
        lp.width = ScreenUtil.getScreenWidth(getContext());
        o.setAttributes(lp);
        this.getWindow().setGravity(Gravity.BOTTOM);
        this.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
    }

    private class RoamAdapter extends BaseQuickAdapter<RoamBean, BaseViewHolder> {

        public RoamAdapter(int layoutResId, @Nullable List<RoamBean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, RoamBean item) {

            helper.addOnClickListener(R.id.tv_roam);
            helper.setText(R.id.tv_roam, item.getRoamingTimeStr());

        }
    }

    public interface OnMsgSaveDaysDialogClickListener {

        void itemClick(double roamingTime, String roamingTimeStr);
    }
}
